Rust Mqtt Encoding & Decoding
Mqttrs
is a Rust crate (library) to write MQTT
protocol clients and servers.
It is a codec-only library with very few dependencies and a straightworward and composable API, usable with rust's standard library or with async frameworks like tokio.
Mqttrs
currently requires Rust >= 1.32 and supports
MQTT 3.1.1. Support for MQTT
5 is planned for a future version.
Usage
Add mqttrs = "0.2"
to your Cargo.toml
.
use *;
use BytesMut;
// Allocate write buffer.
let mut buf = with_capacity;
// Encode an MQTT Connect packet.
let pkt = Connect;
assert!;
assert_eq!;
let mut encoded = buf.clone;
// Decode one packet. The buffer will advance to the next packet.
assert_eq!;
// Example decode failures.
let mut incomplete = encoded.split_to;
assert_eq!;
let mut garbage = from;
assert_eq!;